<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    var lengthOfLastWord = function (s) {
        console.log(s.length - 1);
        let count = 0;
        let number = [];
        for (let i = 0; i < s.length; i++) {
            if (s[i] != ' ') {
                count++;
                if (i == s.length - 1) {
                    number.push(count);
                }
            } else {
                console.log(i);
                if (count != 0) {
                    number.push(count);
                }
                count = 0;
            }
        }
        console.log(number);
        return number[number.length - 1];
    };
    let s = "luffy is still joyboy dfghfd  fghj";
    console.log(lengthOfLastWord(s));
</script>

</html>